//
//  WBStatusListViewModel.swift
//  WSWeibo
//
//  Created by guojianfeng on 2017/7/24.
//  Copyright © 2017年 guojianfeng. All rights reserved.
//

import Foundation

///微博视图模型
///是否继承    使用KVC 需要继承NSObject
///只有函数逻辑 不用集成
class WBStatusListViewModel {
    
    lazy var statusList = [WBStatus]()
    func loadStatus(pullup: Bool, completion:@escaping (_ isSuccess: Bool) -> ())  {
        let since_id = pullup ? 0 : (self.statusList.first?.id ?? 0)
        let max_id =  !pullup ? 0 : (self.statusList.last?.id ?? 0)
        WBNetWorkingManager.shared.statusList(since_id: since_id,max_id: max_id) { (list, isSuccess) in
            guard  let array = NSArray.yy_modelArray(with: WBStatus.self, json: list ?? []) as? [WBStatus] else{
                completion(isSuccess)
                return
            }
            self.statusList = pullup ?  self.statusList + array : array + self.statusList
            completion(isSuccess)
        }
    }
}
